from django.db import models

# Create your models here.
class Companylist (models.Model):
    rentcompany = models.CharField(max_length=40, blank=True, null=True, verbose_name="租赁公司名称")
    class Meta:
        verbose_name = "公司信息表"
        verbose_name_plural = verbose_name
    def __str__(self):
        return self.rentcompany

class Devicelist (models.Model):
    name = models.CharField(max_length=40, blank=True, null=True, verbose_name="资产名称")
    model = models.CharField(max_length=40, blank=True, null=True, verbose_name="资产型号")
    type = models.CharField(max_length=40, blank=True, null=True, verbose_name="资产品牌")
    class Meta:
        verbose_name = "设备信息表"
        verbose_name_plural = verbose_name
    def __str__(self):
        return self.name


class RentDevice (models.Model):
    device = models.ForeignKey(Devicelist, on_delete=models.CASCADE, verbose_name="设备名称")
    company =  models.ForeignKey(Companylist, on_delete=models.CASCADE, verbose_name="公司别")
    flag = models.CharField(max_length=40, blank=True, null=True, verbose_name="旗帜位")
    status = models.IntegerField(null=True, blank=True, default=0, verbose_name="类别状态")
    rentprice = models.DecimalField(max_digits=8, decimal_places=3, blank=True, null=True, verbose_name="租赁价格")
    renttime = models.IntegerField(verbose_name="租赁周期")
    memo = models.TextField(max_length=500, blank=True)  # 备注
    timesstamps = models.DateField(auto_now=True, verbose_name="更新时间")
    class Meta:
        verbose_name = "租赁资产信息表"
        verbose_name_plural = verbose_name


class  Departments(models.Model):
    CATEGORY_TYPE=(
        (1, "一级类目"),
        (2, "二级类目"),
        (3, "三级类目"),
    )
    depid =  models.CharField(max_length=40, null=True, blank=True, verbose_name="编号")
    name = models.CharField(max_length=200, null=True, blank=True, verbose_name="名称")
    depmaster  = models.CharField(max_length=200, null=True, blank=True, verbose_name="部门助理邮箱")
    types = models.IntegerField(choices=CATEGORY_TYPE, verbose_name="类目级别")
    parent_types = models.ForeignKey("self", null=True, blank=True, verbose_name="父类别", related_name="sub_cat", on_delete=models.DO_NOTHING)
    class Meta:
        verbose_name = "部门类别"
        verbose_name_plural = verbose_name
    def __str__(self):
        return self.name

class RequestUsers (models.Model):
    device = models.ForeignKey(RentDevice, on_delete=models.CASCADE, verbose_name="设备名称")
    username = models.CharField(max_length=40, blank=True, null=True, verbose_name="资产使用人")
    usercode = models.CharField(max_length=40, blank=True, null=True, verbose_name="资产使用人工号")
    userphone = models.CharField(max_length=40, blank=True, null=True, verbose_name="资产使用人电话")
    usedepartment = models.ForeignKey(Departments, on_delete=models.CASCADE, verbose_name="使用人部门")
    requretime = models.DateField(auto_now=True, verbose_name="需求时间")
    applicant = models.CharField(max_length=40, null=True, blank=True, verbose_name="申请人")
    status = models.IntegerField(null=True, blank=True, default=0, verbose_name="类别状态")
    timesstamps = models.DateField(auto_now=True, verbose_name="更新时间")
    class Meta:
        verbose_name = "电脑需求单"
        verbose_name_plural = verbose_name
    def __str__(self):
        return self.username


class Rentlists (models.Model):
    usedevice = models.ForeignKey(RequestUsers, on_delete=models.CASCADE, verbose_name="设备需求单号")
    serial = models.CharField(max_length=40, blank=True, null=True, verbose_name="资产序列号")
    status = models.IntegerField(null=True, blank=True, default=0, verbose_name="类别状态")
    timesstamps = models.DateField(auto_now=True, verbose_name="更新时间")
    class Meta:
        verbose_name = "电脑使用记录"
        verbose_name_plural = verbose_name
    def __str__(self):
        return self.usedevice